<template>
<div class="app">
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="名字">
      <el-input v-model="form.name" placeholder="请输入名字"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.sex">
        <el-radio label="男"></el-radio>
        <el-radio label="女"></el-radio>
      </el-radio-group>
    </el-form-item>

    <el-form-item label="出生日期">

        <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="form.birthday" style="width: 100%;"></el-date-picker>

    </el-form-item>

    <el-form-item label="公司">
      <el-input v-model="form.company" placeholder="请输入公司名"></el-input>
    </el-form-item>

    <el-form-item label="职位">
      <el-input v-model="form.position" placeholder="请输入职位"></el-input>
    </el-form-item>
    <el-form-item label="手机">
      <el-input v-model="form.mobile" placeholder="请输入手机号"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit" style="width: 100%">立即创建</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import Qs from "qs";

export default {
  name: "CardInsert",
  data(){
    return{
      form: {
        name: '',
        sex: '',
        birthday: '',
        company: '',
        position: '',
        mobile: '',
      }
    }
  },
  methods: {
    onSubmit() {
      let vm = this;
      this.axios({
        url:'/localhost/crad/insert',
        method:'post',
        data:{
          crad:vm.form
        },
        transformRequest:[function (data) {
          console.log(data)
          return Qs.stringify(data.crad)
        }]
      }).then(function (res) {
        console.log(res.data)
        if (res.data.code == 0){
          vm.$message.success("添加成功");
          vm.$router.push("/Home");
        }
      }).catch(function (err) {
        console.log(err);
      });
    }
  }
}
</script>

<style scoped>
.app{
  width: 40%;
  text-align: center;
  margin-top: 3%;
  margin-left: 30%;
}
</style>
